import { Navigate, Route, Routes } from 'react-router-dom'
import KeepAlive from 'react-activation'
import LoignPage from '@/page/LoginRegister/login'
import RegisterPage from '@/page/LoginRegister/register'

const Router = () => {
  const routes = [
    {path: '/login', element: <LoignPage/>},
    {path: '/register', element: <RegisterPage/>}
  ]

  const hasKeepAlive = (item: {path: string, element: HTMLAllCollection}) => {
    return (
      <KeepAlive when={[true, true]} saveScrollPosition={'screen'} key={item.path}>{item.element}</KeepAlive>
    )
  }

  const show = (item: any) => {
    if(item.keepAlive) { // 需要缓存
      return (
       <Route path={item.path} element={hasKeepAlive(item)}>item.children && RouteNav(item.children)</Route>
      )
    } else { // 不需要缓存
      return (
        <Route path={item.path} element={item.element}>item.children && RouteNav(item.children)</Route>
      )
    }
  }

  const RouteNav = (params: any) => {}
}

export default Router